define([],function(){
	return {
		statusToName:{'49':'展示期','50':'认购期','53':'流通期','54':'交易结束','55':'认购结束'},
		status_zsq:49,
		status_rgq:50,
		status_ltq:53,
		status_jyjs:54,
		status_rgjs:55,
	   	goodsOriginal:{}, // 原始商品数据
	   	codeToGoods:{}, // key为商品代码，值为多个商品对象
	   	gidToGoods:{}, // key为商品分类id，值为多个商品对象
	   	codeToFlashsale:{}, // 进行中的抢购商品
	   	codeToFlashsalenext:{}, // 还没开始的的抢购商品
	   	addGoods:function(data){
	   		this.gidToGoods={};//重置数据，避免重复追加
	   		this.codeToGoods={}
	   		this.goodsOriginal=data;
	   		var sort_a=[],
		    	goods;
		    
		    for (i in this.goodsOriginal) {
        		goods = this.goodsOriginal[i];
        		
        		if(goods.groupid==='0'){continue;}
        		if(this.gidToGoods[goods.groupid]){//改组已经有数据就追加
        			this.gidToGoods[goods.groupid].push(goods);
        		}else{//改组还没数据
	    			this.gidToGoods[goods.groupid]=[goods];
        		}
        		this.codeToGoods[goods.goodscode]=goods;
        		
        		if(goods.issuestatus==this.status_rgq){//认购期
					//有抢购活动
					if(typeof goods.flashsale != 'undefined'){
						// 0-没开始 1-正在抢购
						if(goods.flashsale.status==='1'){
	                        this.codeToFlashsale[goods.goodscode]=goods;
						}
						if(goods.flashsale.status==='0' || typeof goods.flashsalenext != 'undefined'){
							this.codeToFlashsalenext[goods.goodscode]=goods;
						}
					}
				}
        		
        		sort_a.push(goods.showorder+','+goods.goodscode);
        	}

		    sort_a.sort(function(a,b){
		        var ia=a.split(',')[0],
		            ib=b.split(',')[0];
		        return ia-ib;
		    })
	   },
	   // 是否有正在进行抢购
	   getFlashsale:function(goods){
   			if(goods.issuestatus==50){//认购期
				//有抢购活动
				if(typeof goods.flashsale != 'undefined'){
					// 0-没开始 1-正在抢购
					if(goods.flashsale.status==='1'){
                        return goods.flashsale;
					}
				}
			}
   			return false;
	   },
	   // 是否有下一场
	   getFlashsalenext:function(goods){
   			if(goods.issuestatus==50){
				//有抢购活动
				if(typeof goods.flashsale != 'undefined'){
					// 0-没开始 1-正在抢购
					if(goods.flashsale.status==='0'){
						return goods.flashsale;
					}
				}
				if(typeof goods.flashsalenext != 'undefined'){
					return goods.flashsalenext;
				}
			}
   			return false;
	   }
	}
});